package com.anlu.pattern.action.template;

import com.anlu.pattern.action.strategy.Discount;
import com.anlu.pattern.action.strategy.FullDiscount;
import com.anlu.pattern.action.strategy.NewerDiscount;
import com.anlu.pattern.action.strategy.SecondDiscount;
import com.anlu.pattern.create.factory.simple.StaticFactory;
import com.anlu.pattern.common.entity.Fruit;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShoppingCartClient {
    private static Map<String, Discount> discountMap = new HashMap<>();

    static {
        discountMap.put("full",new FullDiscount());
        discountMap.put("newer",new NewerDiscount());
        discountMap.put("second",new SecondDiscount());
    }

    public static void main(String[] args) {
        List<Fruit> products = new ArrayList();

        products.add(StaticFactory.getFruitApple());
        products.add(StaticFactory.getFruitBanana());
        products.add(StaticFactory.getFruitOrange());

        //获取购物车
        ShoppingCart cart = new OtherPayShopping(products);

        //策略模式注入优惠方案
        String discount="second";
        cart.setDiscount(discountMap.get(discount));
        cart.submitOrder();
    }
}
